package com.zhao.fishingguideserver.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zhao.fishingguideserver.POJO.Fish;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 鱼类信息数据访问接口
 */
@Mapper
public interface FishMapper extends BaseMapper<Fish> {
    
    @Select("SELECT id, species_name, habitat_diet, distribution, economic_significance, fish_img_url, Recommended_fishing_methods " +
            "FROM freshwater_fish_china_1979")
    List<Fish> selectAll();
    
    @Select("SELECT id, species_name, habitat_diet, distribution, economic_significance, fish_img_url, Recommended_fishing_methods " +
            "FROM freshwater_fish_china_1979 " +
            "WHERE id = #{id}")
    Fish selectById(@Param("id") Integer id);
    
    @Select("SELECT id, species_name, habitat_diet, distribution, economic_significance, fish_img_url, Recommended_fishing_methods " +
            "FROM freshwater_fish_china_1979 " +
            "WHERE species_name LIKE CONCAT('%', #{keyword}, '%') " +
            "OR habitat_diet LIKE CONCAT('%', #{keyword}, '%') " +
            "OR distribution LIKE CONCAT('%', #{keyword}, '%') " +
            "OR Recommended_fishing_methods LIKE CONCAT('%', #{keyword}, '%')")
    List<Fish> searchByKeyword(@Param("keyword") String keyword);
    
    @Select("SELECT id, species_name, habitat_diet, distribution, economic_significance, fish_img_url, Recommended_fishing_methods " +
            "FROM freshwater_fish_china_1979 " +
            "WHERE habitat_diet LIKE CONCAT('%', #{habitat}, '%')")
    List<Fish> filterByHabitat(@Param("habitat") String habitat);
    
    @Select("SELECT id, species_name, habitat_diet, distribution, economic_significance, fish_img_url, Recommended_fishing_methods " +
            "FROM freshwater_fish_china_1979 " +
            "WHERE distribution LIKE CONCAT('%', #{distribution}, '%')")
    List<Fish> filterByDistribution(@Param("distribution") String distribution);
}


